#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    if(argc != 2)
    {
        printf("please input 2 arguments! such as ./a.out <file>\n");
        return -1;
    }

    char buf[100] = "同一个世界！同一个梦想!";
    char *s = buf;;
    int nmem = 0;
    printf("buf=%s\n", buf);

    FILE *fp = fopen(argv[1], "w");
    if(fp == NULL)
    {
        perror("fopen fail");
        return -1;
    }

    // nmem = fread(buf, sizeof(buf), 1, fp);
    nmem = fwrite(buf, sizeof(buf), 1, fp);
    printf("nmem=%d, buf=%s", nmem, buf);

    nmem = fread(s, sizeof(buf), 1, fp);
    printf("nmem=%d, s=%s\n", nmem, s);
    return 0;
}